﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for StatisticBusiness
/// </summary>
public class StatisticBusiness
{
    StatisticData s = new StatisticData();

	public StatisticBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    //public bool Insert(StatisticEntities item)
    //{
    //    return s.Insert(item);
    //}


    //public bool Update(StatisticEntities item)
    //{
    //    return s.Update(item);
    //}
    //public System.Collections.ArrayList getALL()
    //{
    //    System.Collections.ArrayList items = new System.Collections.ArrayList();
    //    SqlDataReader read = s.getAll();
    //    StatisticEntities item = null;
    //    if (read.HasRows)
    //    {
    //        while (read.Read())
    //        {
    //            item = new StatisticItem();
    //            item.ID = int.Parse(read["id"].ToString());
    //            item.Today = read["today"].ToString();
    //            item.Visited = read["visited"].ToString();
    //            items.Add(item);
    //            item = null;
    //        }
    //        read.Close();
    //    }
    //    return items;
    //}

    public bool Update(StatisticEntities item)
    {
        return s.Update(item);
    }
    public System.Collections.ArrayList getALL()
    {
        System.Collections.ArrayList items = new System.Collections.ArrayList();
        SqlDataReader read = s.getAll();
        StatisticEntities item = null;
        if (read.HasRows)
        {
            while (read.Read())
            {
                item = new StatisticEntities();
                item._id = int.Parse(read["id"].ToString());
                item._today = read["today"].ToString();
                item._visited = int.Parse(read["visited"].ToString());
                items.Add(item);
                item = null;
            }
            read.Close();
        }
        return items;
    }

    //public string Day()//Thoi gian ban ghi cuoi cung csdl
    //{
    //    string result = "";
    //    System.Collections.ArrayList items = this.getALL();
    //    StatisticEntities item = null;
    //    if (items != null)
    //    {
    //        item = (StatisticEntities)items[0];
    //        result = item.Today;
    //    }
    //    return result;
    //}

    public string Day()//Thoi gian ban ghi cuoi cung csdl
    {
        string result = "";
        System.Collections.ArrayList items = this.getALL();
        StatisticEntities item = null;
        if (items != null)
        {
            item = (StatisticEntities)items[0];
            result = item._today;
        }
        return result;
    }

    //Lay ve survey duoc nhieu nguoi dang ki nhat
    //public System.Collections.ArrayList SurveyMax()
    //{
    //    System.Collections.ArrayList items = new System.Collections.ArrayList();
    //    System.Collections.ArrayList tmp = new System.Collections.ArrayList();
    //    System.Collections.ArrayList surveys = new SurveyImpl().getALLSurvey();
    //    System.Collections.ArrayList surveylist = new SurveyListImpl().getALLSurvey();
    //    SurveyItem item = null;
    //    SurveyItem itemMax = null;
    //    SurveyListItem itemlist = null;
    //    int record = 0;
    //    for (int i = 0; i < surveys.Count; i++)
    //    {
    //        item = (SurveyItem)surveys[i];
    //        for (int j = 0; j < surveylist.Count; j++)
    //        {
    //            itemlist = (SurveyListItem)surveylist[j];
    //            if (item.ID == itemlist.Survey_ID)
    //            {
    //                record = record + 1;
    //            }
    //        }
    //        itemMax = new SurveyItem();
    //        itemMax.ID = item.ID;
    //        itemMax.Visited = record.ToString();//Luu tam so lan sat hien
    //        items.Add(itemMax);
    //        itemMax = null;
    //        record = 0;
    //    }
    //    //max array
    //    if (items != null)
    //    {
    //        itemMax = (SurveyItem)items[0];
    //        int max = int.Parse(itemMax.Visited);
    //        int id = itemMax.ID;
    //        itemMax = null;
    //        for (int k = 0; k < items.Count; k++)
    //        {
    //            itemMax = (SurveyItem)items[k];
    //            if (max < int.Parse(itemMax.Visited))
    //            {
    //                max = int.Parse(itemMax.Visited);
    //                id = itemMax.ID;
    //            }
    //            itemMax = null;
    //        }
    //        itemMax = new SurveyItem();
    //        itemMax.Visited = max.ToString();
    //        itemMax.ID = id;
    //        tmp.Add(itemMax);
    //    }
    //    return tmp;
    //}
}
